// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    tabs: [{
        name: '现状下', //做某事如何(预测结果)
        type: 'what',
        types: 1,
        end: '预测结果',
        value: '',
        showClose: false,
        showSuccess:false
      },
      {
        name: '现状下', //某件事未来发展如何(预测及评估)
        type: 'what',
        types: 2,
        end: '预测及评估',
        value: '',
        showClose: false,
        showSuccess:false
      },
      {
        name: '现状下', //如何做可以达成某个目的(如何改进)
        type: 'how',
        types: 3,
        end: '如何改进',
        value: '',
        showClose: false,
        showSuccess:false
      },
    ],
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  // 页面跳转
  toLog(e) {
    console.log(this.data.tabs);
    let types = e.currentTarget.dataset.types
    if (types) {
      wx.navigateTo({
        url: '/pages/loading/loading?types=' + types,
      })
    } else {
      wx.navigateTo({
        url: '/pages/loading/loading?types=' + types,
      })
    }
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  onShow() {
    setTimeout(() => {
      app.sliderightshow(this, 'slide_up', 30, 1)
      this.setData({
        tabs: [{
            name: '现状下', //做某事如何(预测结果)
            type: 'what',
            types: 1,
            end: '预测结果',
            value: '',
            showClose: false,
            showSuccess:false
          },
          {
            name: '现状下', //某件事未来发展如何(预测及评估)
            type: 'what',
            types: 2,
            end: '预测及评估',
            value: '',
            showClose: false,
            showSuccess:false
          },
          {
            name: '现状下', //如何做可以达成某个目的(如何改进)
            type: 'how',
            types: 3,
            end: '如何改进',
            value: '',
            showClose: false,
            showSuccess:false
          },
        ]
      })
    }, 1000);
  },
  onHide() {
    setTimeout(() => {
      app.sliderightshow(this, 'slide_up', 0, 0)
    }, 1000);
  },
  setDisabled: function (e) {
    this.setData({
      disabled: !this.data.disabled
    })
  },
  what(e) {
    wx.navigateTo({
      url: '../logs/logs?id=what'
    })
  },
  how(e) {
    wx.navigateTo({
      url: '../logs/logs?id=how'
    })
  },
  // 点击确定输入内容
  confirmInput(e) {
    let index = e.target.dataset.index
    this.setData({
      ['tabs[' + index + '].showClose']: false,
      ['tabs[' + index + '].showSuccess']: false,
    })
  },
  // 输入内容
  inputValue(e) {
    let {value} = e.detail
    let index = e.target.dataset.index
    this.setData({
      ['tabs[' + index + '].showClose']: value?true:false,
      ['tabs[' + index + '].showSuccess']: value?true:false
    })
  },
  // 聚焦事件
  focusValue(e) {
    let {value} = e.detail
    let index = e.target.dataset.index
    this.setData({
      ['tabs[' + index + '].showClose']: value?true:false,
      ['tabs[' + index + '].showSuccess']: value?true:false
    })
  },
  // 失焦事件
  // blurValue(e) {
  //   console.log(e)
  //   let {value} = e.detail
  //   let index = e.target.dataset.index
  //   console.log(this.data.flag)
  //   this.setData({
  //     ['tabs[' + index + '].value']: this.data.flag?'':value,
  //     ['tabs[' + index + '].showClose']: false,
  //     ['tabs[' + index + '].showSuccess']: false,
  //     flag:false,
  //   })
  // },
  successValue(e) {
    console.log(e)
    let index = e.target.dataset.index
    this.setData({
      ['tabs[' + index + '].showClose']: false,
      ['tabs[' + index + '].showSuccess']: false,
    })
  },
  closeValue(e) {
    let index = e.target.dataset.index
    this.setData({
      ['tabs[' + index + '].value']: '',
      ['tabs[' + index + '].showClose']: false,
      ['tabs[' + index + '].showSuccess']: false,
    })
  },
})